home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 January: Mac OS SDK / Dev.CD Jan 99 SDK1.toast / Development Kits / Interfaces&Libraries / Universal / Interfaces / CIncludes / MixedMode.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-17  |  25.2 KB  |  687 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        MixedMode.h
  3.  
  4.      Contains:    Mixed Mode Manager Interfaces.
  5.  
  6.      Version:    Technology:    Mac OS 8
  7.                  Release:    Universal Interfaces 3.2
  8.  
  9.      Copyright:    © 1992-1998 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __MIXEDMODE__
  18. #define __MIXEDMODE__
  19.  
  20. #ifndef __MACTYPES__
  21. #include <MacTypes.h>
  22. #endif
  23.  
  24.  
  25.  
  26. #if PRAGMA_ONCE
  27. #pragma once
  28. #endif
  29.  
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33.  
  34. #if PRAGMA_IMPORT
  35. #pragma import on
  36. #endif
  37.  
  38. #if PRAGMA_STRUCT_ALIGN
  39.     #pragma options align=mac68k
  40. #elif PRAGMA_STRUCT_PACKPUSH
  41.     #pragma pack(push, 2)
  42. #elif PRAGMA_STRUCT_PACK
  43.     #pragma pack(2)
  44. #endif
  45.  
  46. /* Mixed Mode constants */
  47. /* Current Routine Descriptor Version */
  48.  
  49. enum {
  50.     kRoutineDescriptorVersion    = 7
  51. };
  52.  
  53. /* MixedModeMagic Magic Cookie/Trap number */
  54.  
  55. enum {
  56.     _MixedModeMagic                = 0xAAFE
  57. };
  58.  
  59. /* MixedModeState Version for CFM68K Mixed Mode */
  60.  
  61. enum {
  62.     kCurrentMixedModeStateRecord = 1
  63. };
  64.  
  65. /* Calling Conventions */
  66. typedef unsigned short                     CallingConventionType;
  67.  
  68. enum {
  69.     kPascalStackBased            = 0,
  70.     kCStackBased                = 1,
  71.     kRegisterBased                = 2,
  72.     kD0DispatchedPascalStackBased = 8,
  73.     kD1DispatchedPascalStackBased = 12,
  74.     kD0DispatchedCStackBased    = 9,
  75.     kStackDispatchedPascalStackBased = 14,
  76.     kThinkCStackBased            = 5
  77. };
  78.  
  79. /* ISA Types */
  80. typedef SInt8                             ISAType;
  81.  
  82. enum {
  83.     kM68kISA                    = 0,
  84.     kPowerPCISA                    = 1
  85. };
  86.  
  87. /* RTA Types */
  88. typedef SInt8                             RTAType;
  89.  
  90. enum {
  91.     kOld68kRTA                    = 0 << 4,
  92.     kPowerPCRTA                    = 0 << 4,
  93.     kCFM68kRTA                    = 1 << 4
  94. };
  95.  
  96.  
  97. #if TARGET_CPU_PPC
  98.     #define        GetCurrentISA()        ((ISAType) kPowerPCISA)
  99.     #define        GetCurrentRTA()        ((RTAType) kPowerPCRTA)
  100. #elif TARGET_CPU_68K
  101.     #define        GetCurrentISA()        ((ISAType) kM68kISA)
  102.     #if TARGET_RT_MAC_CFM
  103.         #define    GetCurrentRTA()        ((RTAType) kCFM68kRTA)
  104.     #else
  105.         #define    GetCurrentRTA()        ((RTAType) kOld68kRTA)
  106.     #endif
  107. #endif
  108. #define        GetCurrentArchitecture()    (GetCurrentISA() | GetCurrentRTA())
  109.  
  110. /* Constants for specifing 68k registers */
  111.  
  112. enum {
  113.     kRegisterD0                    = 0,
  114.     kRegisterD1                    = 1,
  115.     kRegisterD2                    = 2,
  116.     kRegisterD3                    = 3,
  117.     kRegisterD4                    = 8,
  118.     kRegisterD5                    = 9,
  119.     kRegisterD6                    = 10,
  120.     kRegisterD7                    = 11,
  121.     kRegisterA0                    = 4,
  122.     kRegisterA1                    = 5,
  123.     kRegisterA2                    = 6,
  124.     kRegisterA3                    = 7,
  125.     kRegisterA4                    = 12,
  126.     kRegisterA5                    = 13,
  127.     kRegisterA6                    = 14,                            /* A7 is the same as the PowerPC SP */
  128.     kCCRegisterCBit                = 16,
  129.     kCCRegisterVBit                = 17,
  130.     kCCRegisterZBit                = 18,
  131.     kCCRegisterNBit                = 19,
  132.     kCCRegisterXBit                = 20
  133. };
  134.  
  135. typedef unsigned short                     registerSelectorType;
  136. /* SizeCodes we use everywhere */
  137.  
  138. enum {
  139.     kNoByteCode                    = 0,
  140.     kOneByteCode                = 1,
  141.     kTwoByteCode                = 2,
  142.     kFourByteCode                = 3
  143. };
  144.  
  145. /* Mixed Mode Routine Records */
  146. typedef unsigned long                     ProcInfoType;
  147. /* Routine Flag Bits */
  148. typedef unsigned short                     RoutineFlagsType;
  149.  
  150. enum {
  151.     kProcDescriptorIsAbsolute    = 0x00,
  152.     kProcDescriptorIsRelative    = 0x01
  153. };
  154.  
  155.  
  156. enum {
  157.     kFragmentIsPrepared            = 0x00,
  158.     kFragmentNeedsPreparing        = 0x02
  159. };
  160.  
  161.  
  162. enum {
  163.     kUseCurrentISA                = 0x00,
  164.     kUseNativeISA                = 0x04
  165. };
  166.  
  167.  
  168. enum {
  169.     kPassSelector                = 0x00,
  170.     kDontPassSelector            = 0x08
  171. };
  172.  
  173.  
  174. enum {
  175.     kRoutineIsNotDispatchedDefaultRoutine = 0x00,
  176.     kRoutineIsDispatchedDefaultRoutine = 0x10
  177. };
  178.  
  179.  
  180. enum {
  181.     kProcDescriptorIsProcPtr    = 0x00,
  182.     kProcDescriptorIsIndex        = 0x20
  183. };
  184.  
  185.  
  186. struct RoutineRecord {
  187.     ProcInfoType                     procInfo;                    /* calling conventions */
  188.     SInt8                             reserved1;                    /* Must be 0 */
  189.     ISAType                         ISA;                        /* Instruction Set Architecture */
  190.     RoutineFlagsType                 routineFlags;                /* Flags for each routine */
  191.     ProcPtr                         procDescriptor;                /* Where is the thing we’re calling? */
  192.     UInt32                             reserved2;                    /* Must be 0 */
  193.     UInt32                             selector;                    /* For dispatched routines, the selector */
  194. };
  195. typedef struct RoutineRecord            RoutineRecord;
  196. typedef RoutineRecord *                    RoutineRecordPtr;
  197. typedef RoutineRecordPtr *                RoutineRecordHandle;
  198. /* Mixed Mode Routine Descriptors */
  199. /* Definitions of the Routine Descriptor Flag Bits */
  200.  
  201. typedef UInt8                             RDFlagsType;
  202.  
  203. enum {
  204.     kSelectorsAreNotIndexable    = 0x00,
  205.     kSelectorsAreIndexable        = 0x01
  206. };
  207.  
  208. /* Routine Descriptor Structure */
  209.  
  210. struct RoutineDescriptor {
  211.     UInt16                             goMixedModeTrap;            /* Our A-Trap */
  212.     SInt8                             version;                    /* Current Routine Descriptor version */
  213.     RDFlagsType                     routineDescriptorFlags;        /* Routine Descriptor Flags */
  214.     UInt32                             reserved1;                    /* Unused, must be zero */
  215.     UInt8                             reserved2;                    /* Unused, must be zero */
  216.     UInt8                             selectorInfo;                /* If a dispatched routine, calling convention, else 0 */
  217.     UInt16                             routineCount;                /* Number of routines in this RD */
  218.     RoutineRecord                     routineRecords[1];            /* The individual routines */
  219. };
  220. typedef struct RoutineDescriptor        RoutineDescriptor;
  221. typedef RoutineDescriptor *                RoutineDescriptorPtr;
  222. typedef RoutineDescriptorPtr *            RoutineDescriptorHandle;
  223. /* 68K MixedModeStateRecord */
  224.  
  225. struct MixedModeStateRecord {
  226.     UInt32                             state1;
  227.     UInt32                             state2;
  228.     UInt32                             state3;
  229.     UInt32                             state4;
  230. };
  231. typedef struct MixedModeStateRecord        MixedModeStateRecord;
  232. /* Macros for building static Routine Descriptors */
  233.  
  234. /* A macro which creates a static instance of a non-dispatched routine descriptor */
  235. #define BUILD_ROUTINE_DESCRIPTOR(procInfo, procedure)                                 \
  236.     {                                                                                \
  237.         _MixedModeMagic,                            /* Mixed Mode A-Trap */         \
  238.         kRoutineDescriptorVersion,                    /* version */                    \
  239.         kSelectorsAreNotIndexable,                    /* RD Flags - not dispatched */    \
  240.         0,                                            /* reserved 1 */                \
  241.         0,                                            /* reserved 2 */                \
  242.         0,                                            /* selector info */                \
  243.         0,                                            /* number of routines */        \
  244.         {                                            /* It’s an array */                \
  245.             {                                        /* It’s a struct */                \
  246.                 (procInfo),                            /* the ProcInfo */                \
  247.                 0,                                    /* reserved */                    \
  248.                 GetCurrentArchitecture(),             /* ISA and RTA */                \
  249.                 kProcDescriptorIsAbsolute |            /* Flags - it’s absolute addr */\
  250.                 kFragmentIsPrepared |                /* It’s prepared */                \
  251.                 kUseNativeISA,                        /* Always use native ISA */        \
  252.                 (ProcPtr)(procedure),                /* the procedure */                \
  253.                 0,                                    /* reserved */                    \
  254.                 0                                    /* Not dispatched */            \
  255.             }                                                                        \
  256.         }                                                                            \
  257.     }
  258.  
  259. /* a macro which creates a static instance of a fat routine descriptor */
  260. #define BUILD_FAT_ROUTINE_DESCRIPTOR(m68kProcInfo, m68kProcPtr, powerPCProcInfo, powerPCProcPtr)  \
  261.     {                                                                                \
  262.         _MixedModeMagic,                            /* Mixed Mode A-Trap */         \
  263.         kRoutineDescriptorVersion,                    /* version */                    \
  264.         kSelectorsAreNotIndexable,                    /* RD Flags - not dispatched */    \
  265.         0,                                            /* reserved */                    \
  266.         0,                                            /* reserved */                    \
  267.         0,                                            /* reserved */                    \
  268.         1,                                            /* Array count */                \
  269.         {                                            /* It’s an array */                \
  270.             {                                        /* It’s a struct */                \
  271.                 (m68kProcInfo),                        /* the ProcInfo */                \
  272.                 0,                                    /* reserved */                    \
  273.                 kM68kISA |                            /* ISA */                        \
  274.                 kOld68kRTA,                            /* RTA */                        \
  275.                 kProcDescriptorIsAbsolute |            /* Flags - it’s absolute addr */\
  276.                 kUseCurrentISA,                        /* Use current ISA */            \
  277.                 (ProcPtr)(m68kProcPtr),                /* the procedure */                \
  278.                 0,                                    /* reserved */                    \
  279.                 0,                                    /* reserved */                    \
  280.             },                                                                        \
  281.             {                                        /* It’s a struct */                \
  282.                 (powerPCProcInfo),                    /* the ProcInfo */                \
  283.                 0,                                    /* reserved */                    \
  284.                 GetCurrentArchitecture(),             /* ISA and RTA */                \
  285.                 kProcDescriptorIsAbsolute |            /* Flags - it’s absolute addr */\
  286.                 kFragmentIsPrepared |                /* It’s prepared */                \
  287.                 kUseCurrentISA,                        /* Always use current ISA */    \
  288.                 (ProcPtr)(powerPCProcPtr),            /* the procedure */                \
  289.                 0,                                    /* reserved */                    \
  290.                 0                                    /* reserved */                    \
  291.             }                                                                        \
  292.         }                                                                            \
  293.     }
  294. /* Mixed Mode ProcInfos */
  295.  
  296. enum {
  297.                                                                 /* Calling Convention Offsets */
  298.     kCallingConventionWidth        = 4,
  299.     kCallingConventionPhase        = 0,
  300.     kCallingConventionMask        = 0x0F,                            /* Result Offsets */
  301.     kResultSizeWidth            = 2,
  302.     kResultSizePhase            = kCallingConventionWidth,
  303.     kResultSizeMask                = 0x30,                            /* Parameter offsets & widths */
  304.     kStackParameterWidth        = 2,
  305.     kStackParameterPhase        = (kCallingConventionWidth + kResultSizeWidth),
  306.     kStackParameterMask            = (long)0xFFFFFFC0,                /* Register Result Location offsets & widths */
  307.     kRegisterResultLocationWidth = 5,
  308.     kRegisterResultLocationPhase = (kCallingConventionWidth + kResultSizeWidth), /* Register Parameter offsets & widths */
  309.     kRegisterParameterWidth        = 5,
  310.     kRegisterParameterPhase        = (kCallingConventionWidth + kResultSizeWidth + kRegisterResultLocationWidth),
  311.     kRegisterParameterMask        = 0x7FFFF800,
  312.     kRegisterParameterSizePhase    = 0,
  313.     kRegisterParameterSizeWidth    = 2,
  314.     kRegisterParameterWhichPhase = kRegisterParameterSizeWidth,
  315.     kRegisterParameterWhichWidth = 3,                            /* Dispatched Stack Routine Selector offsets & widths */
  316.     kDispatchedSelectorSizeWidth = 2,
  317.     kDispatchedSelectorSizePhase = (kCallingConventionWidth + kResultSizeWidth), /* Dispatched Stack Routine Parameter offsets */
  318.     kDispatchedParameterPhase    = (kCallingConventionWidth + kResultSizeWidth + kDispatchedSelectorSizeWidth), /* Special Case offsets & widths */
  319.     kSpecialCaseSelectorWidth    = 6,
  320.     kSpecialCaseSelectorPhase    = kCallingConventionWidth,
  321.     kSpecialCaseSelectorMask    = 0x03F0
  322. };
  323.  
  324.  
  325. enum {
  326.     kSpecialCase                = 0x000F                        /* (CallingConventionType) */
  327. };
  328.  
  329.  
  330. enum {
  331.                                                                 /* all of the special cases enumerated.  The selector field is 6 bits wide */
  332.     kSpecialCaseHighHook        = 0,
  333.     kSpecialCaseCaretHook        = 0,                            /* same as kSpecialCaseHighHook */
  334.     kSpecialCaseEOLHook            = 1,
  335.     kSpecialCaseWidthHook        = 2,
  336.     kSpecialCaseTextWidthHook    = 2,                            /* same as kSpecialCaseWidthHook */
  337.     kSpecialCaseNWidthHook        = 3,
  338.     kSpecialCaseDrawHook        = 4,
  339.     kSpecialCaseHitTestHook        = 5,
  340.     kSpecialCaseTEFindWord        = 6,
  341.     kSpecialCaseProtocolHandler    = 7,
  342.     kSpecialCaseSocketListener    = 8,
  343.     kSpecialCaseTERecalc        = 9,
  344.     kSpecialCaseTEDoText        = 10,
  345.     kSpecialCaseGNEFilterProc    = 11,
  346.     kSpecialCaseMBarHook        = 12
  347. };
  348.  
  349.  
  350. /*
  351.     NOTES ON USING ROUTINE DESCRIPTOR FUNCTIONS
  352.     
  353.     When calling these routine from classic 68k code there are two possible intentions.
  354.  
  355.     The first is source compatibility with code ported to CFM (either PowerPC or 68k CFM). When
  356.     the code is compiled for CFM the functions create routine descriptors that can be used by
  357.     the mixed mode manager operating on that machine. When the code is compiled for classic 68k
  358.     these functions do nothing so that the code will run on Macintoshes that do not have a
  359.     mixed mode manager. The dual nature of these functions is achieved by turning the CFM calls
  360.     into "no-op" macros for classic 68k: You can put "NewRoutineDescriptor" in your source,
  361.     compile it for any runtime or instruction set architecture, and it will run correctly on the
  362.     intended runtime/instruction platform. All without source changes and/or conditional source.
  363.     
  364.     The other intention is for code that "knows" that it is executing as classic 68k runtime
  365.     and is specifically trying to call code of another architecture using mixed mode. Since the
  366.     routines were designed with classic <-> CFM source compatibility in mind this second case
  367.     is treated special. For classic 68k code to create routines descriptors for use by mixed mode
  368.     it must call the "Trap" versions of the routines (NewRoutineDescriptorTrap). These versions
  369.     are only available to classic 68k callers: rigging the interfaces to allow calling them
  370.     from CFM code will result in runtime failure because no shared library implements or exports
  371.     the functions.
  372.     
  373.  
  374.     This almost appears seamless until you consider "fat" routine descriptors and the advent of
  375.     CFM-68K. What does "fat" mean? CFM-68K is not emulated on PowerPC and PowerPC is not emulated
  376.     on CFM-68K. It makes no sense to create a routine descriptor having both a CFM-68K routine
  377.     and a PowerPC native routine pointer. Therefore "fat" is defined to be a mix of classic and
  378.     CFM for the hardware's native instruction set: on PowerPC fat is classic and PowerPC native,
  379.     on a 68k machine with CFM-68K installed fat is classic and CFM-68K.
  380.     
  381.     By definition fat routine descriptors are only constructed by code that is aware of the 
  382.     architecture it is executing as and that another architecture exists. Source compatibility
  383.     between code intented as pure classic and pure CFM is not an issue and so NewFatRoutineDescriptor
  384.     is not available when building pure classic code.
  385.     
  386.     NewFatRoutineDescriptorTrap is available to classic code on both PowerPC and CFM-68K. The
  387.     classic code can use the code fragment manager routine "FindSymbol" to obtain the address of 
  388.     a routine in a shared library and then construct a routine descriptor with both the CFM routine 
  389.     and classic    routine.
  390. */
  391.  
  392. #if TARGET_OS_MAC && TARGET_RT_MAC_CFM
  393. EXTERN_API( UniversalProcPtr )
  394. NewRoutineDescriptor            (ProcPtr                 theProc,
  395.                                  ProcInfoType             theProcInfo,
  396.                                  ISAType                 theISA);
  397.  
  398. EXTERN_API( void )
  399. DisposeRoutineDescriptor        (UniversalProcPtr         theProcPtr);
  400.  
  401. EXTERN_API( UniversalProcPtr )
  402. NewFatRoutineDescriptor            (ProcPtr                 theM68kProc,
  403.                                  ProcPtr                 thePowerPCProc,
  404.                                  ProcInfoType             theProcInfo);
  405.  
  406. #else
  407. #define DisposeRoutineDescriptor(theProcPtr)
  408. #define NewRoutineDescriptor(theProc, theProcInfo, theISA) ((UniversalProcPtr)theProc)
  409. /* Note that the call to NewFatRoutineDescriptor is undefined. */
  410. #endif  /* TARGET_OS_MAC && TARGET_RT_MAC_CFM */
  411.  
  412.  
  413. #if TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  414. /*
  415.     The "Trap" versions of the MixedMode calls are only for classic 68K clients that 
  416.     want to load and use CFM based code.
  417. */
  418. EXTERN_API( UniversalProcPtr )
  419. NewRoutineDescriptorTrap        (ProcPtr                 theProc,
  420.                                  ProcInfoType             theProcInfo,
  421.                                  ISAType                 theISA)                                TWOWORDINLINE(0x7000, 0xAA59);
  422.  
  423. EXTERN_API( void )
  424. DisposeRoutineDescriptorTrap    (UniversalProcPtr         theProcPtr)                            TWOWORDINLINE(0x7001, 0xAA59);
  425.  
  426. EXTERN_API( UniversalProcPtr )
  427. NewFatRoutineDescriptorTrap        (ProcPtr                 theM68kProc,
  428.                                  ProcPtr                 thePowerPCProc,
  429.                                  ProcInfoType             theProcInfo)                        TWOWORDINLINE(0x7002, 0xAA59);
  430.  
  431. #endif  /* TARGET_CPU_68K && !TARGET_RT_MAC_CFM */
  432.  
  433. #if TARGET_RT_MAC_CFM
  434. /*
  435.     CallUniversalProc is only implemented in shared libraries on CFM68K and PowerPC, it is now
  436.     conditionalize with TARGET_RT_MAC_CFM.  This will catch accidental calls from classic 68K code
  437.     that previously only showed up as linker errors.
  438. */
  439. EXTERN_API_C( long )
  440. CallUniversalProc                (UniversalProcPtr         theProcPtr,
  441.                                  ProcInfoType             procInfo,
  442.                                  ...);
  443.  
  444. EXTERN_API_C( long )
  445. CallOSTrapUniversalProc            (UniversalProcPtr         theProcPtr,
  446.                                  ProcInfoType             procInfo,
  447.                                  ...);
  448.  
  449. #endif  /* TARGET_RT_MAC_CFM */
  450.  
  451. #if TARGET_CPU_68K
  452. EXTERN_API( OSErr )
  453. SaveMixedModeState                (MixedModeStateRecord *    stateStorage,
  454.                                  UInt32                 stateVersion)                        TWOWORDINLINE(0x7003, 0xAA59);
  455.  
  456. EXTERN_API( OSErr )
  457. RestoreMixedModeState            (MixedModeStateRecord *    stateStorage,
  458.                                  UInt32                 stateVersion)                        TWOWORDINLINE(0x7004, 0xAA59);
  459.  
  460. #endif  /* TARGET_CPU_68K */
  461.  
  462. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
  463.  *
  464.  *    Macros for building ProcInfos.  Examples:
  465.  *    
  466.  *    
  467.  *    uppModalFilterProcInfo = kPascalStackBased
  468.  *         | RESULT_SIZE(SIZE_CODE(sizeof(Boolean)))
  469.  *         | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DialogPtr)))
  470.  *         | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(EventRecord*)))
  471.  *         | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short*))),
  472.  *
  473.  *    uppDeskHookProcInfo = kRegisterBased
  474.  *         | REGISTER_ROUTINE_PARAMETER(1, kRegisterD0, SIZE_CODE(sizeof(Boolean)))
  475.  *         | REGISTER_ROUTINE_PARAMETER(2, kRegisterA0, SIZE_CODE(sizeof(EventRecord*)))
  476.  *
  477.  *    uppGXSpoolResourceProcInfo = kCStackBased
  478.  *         | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  479.  *         | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(gxSpoolFile)))
  480.  *         | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Handle)))
  481.  *         | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(ResType)))
  482.  *         | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(long)))
  483.  *
  484.  *    uppTEFindWordProcInfo = SPECIAL_CASE_PROCINFO( 6 ),
  485.  *
  486.  */
  487.  
  488.  
  489. /* * * * * * * * * * * * * * 
  490.  *    SIZE_CODE -     Return the size code for an object, given its size in bytes.
  491.  *        size - size of an object in bytes
  492.  */
  493. #define SIZE_CODE(size) \
  494.     (((size) == 4) ? kFourByteCode : (((size) == 2) ? kTwoByteCode : (((size) == 1) ? kOneByteCode : 0)))
  495.  
  496.  
  497. /* * * * * * * * * * * * * * 
  498.  *    RESULT_SIZE -     Return the result field of a ProcInfo, given the return object’s size.
  499.  *                     This is the same for all ProcInfos
  500.  *        sizeCode - size code
  501.  */
  502. #define RESULT_SIZE(sizeCode) \
  503.     ((ProcInfoType)(sizeCode) << kResultSizePhase)
  504.  
  505.  
  506. /* * * * * * * * * * * * * * 
  507.  *    STACK_ROUTINE_PARAMETER -    Return a parameter field of a ProcInfo, for a simple,
  508.  *                                non-dispatched, stack based routine.
  509.  *        whichParam - which parameter
  510.  *        sizeCode - size code
  511.  */
  512. #define STACK_ROUTINE_PARAMETER(whichParam, sizeCode) \
  513.     ((ProcInfoType)(sizeCode) << (kStackParameterPhase + (((whichParam) - 1) * kStackParameterWidth)))
  514.  
  515.  
  516. /* * * * * * * * * * * * * * 
  517.  *    DISPATCHED_STACK_ROUTINE_PARAMETER -    Return a parameter field of a ProcInfo, for 
  518.  *                                            a dispatched, stack based routine.  The same
  519.  *                                            macro is used regardless of the type of
  520.  *                                            dispatching.
  521.  *        whichParam - which parameter
  522.  *        sizeCode - size code
  523.  */
  524. #define DISPATCHED_STACK_ROUTINE_PARAMETER(whichParam, sizeCode) \
  525.     ((ProcInfoType)(sizeCode) << (kDispatchedParameterPhase + (((whichParam) - 1) * kStackParameterWidth)))
  526.  
  527.  
  528. /* * * * * * * * * * * * * * 
  529.  *    DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE -    Return a the selector size field of a ProcInfo
  530.  *                                                for a dispatched, stack based routine.  The
  531.  *                                                same macro is used regardless of the type of
  532.  *                                                dispatching.
  533.  *        sizeCode - size code 
  534.  */
  535. #define DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(sizeCode) \
  536.     ((ProcInfoType)(sizeCode) << kDispatchedSelectorSizePhase)
  537.  
  538.  
  539. /* * * * * * * * * * * * * * 
  540.  *    REGISTER_RESULT_LOCATION -        Return the Result Location field of a ProcInfo, 
  541.  *                                    given the location.
  542.  *        whichReg - which register
  543.  */
  544. #define REGISTER_RESULT_LOCATION(whichReg) \
  545.     ((ProcInfoType)(whichReg) << kRegisterResultLocationPhase)
  546.  
  547.  
  548. /* * * * * * * * * * * * * * 
  549.  *    REGISTER_ROUTINE_PARAMETER -    Return a parameter field of a ProcInfo for a 
  550.  *                                    register based routine.
  551.  */
  552. #define REGISTER_ROUTINE_PARAMETER(whichParam, whichReg, sizeCode) \
  553.     ((((ProcInfoType)(sizeCode) << kRegisterParameterSizePhase) | ((ProcInfoType)(whichReg) << kRegisterParameterWhichPhase)) << \
  554.             (kRegisterParameterPhase + (((whichParam) - 1) * kRegisterParameterWidth)))
  555.  
  556.  
  557. /* * * * * * * * * * * * * * 
  558.  *
  559.  *    SPECIAL_CASE_PROCINFO -     Returns the procInfo constant for the following special cases:
  560.  *    
  561.  *        High Hook & Caret Hook -  (see I-379)
  562.  *            C calling conventions, Rect on stack, pointer in A3, no return value
  563.  *        EOL Hook - (see VI-15-26)
  564.  *            Register-based; inputs in D0, A3, A4; 
  565.  *            output is Z flag of status register
  566.  *        Width Hook - (see VI-15-27)
  567.  *            Register-based; inputs in D0, D1, A0, A3, A4; output in D1 
  568.  *        NWidth Hook - (see VI-15-27)
  569.  *            Register-based; inputs in D0, D1, D2, A0, A2, A3, A4; output in D1 
  570.  *        TextWidthHook - (see VI-15-28)
  571.  *            Register-based; inputs in D0, D1, A0, A3, A4; output in D1 
  572.  *        DrawHook - (see VI-15-28)
  573.  *            Register-based; inputs in D0, D1, A0, A3, A4; no output
  574.  *        HitTestHook - (See VI-15-29)
  575.  *            Register-based; inputs in D0, D1, D2, A0, A3, A4; outputs in D0, D1, D2
  576.  *        FindWord -  (see VI-15-30)
  577.  *            Register-based; inputs in D0, D2, A3, A4; outputs in D0, D1
  578.  *        ADBRoutines - (see V-371)
  579.  *            Register-based; inputs in A0, A1, A2, D0; no outputs
  580.  *        ProtocolHandler - (see II-326)
  581.  *            Register-based; inputs in A0, A1, A2, A3, A4, D1.w; output in Z 
  582.  *        SocketListener - (see II-329)
  583.  *            Register-based; inputs in A0, A1, A2, A3, A4, D0.b, D1.w; output in Z 
  584.  *        Reclac - (see I-391)
  585.  *            Register-based; inputs in A3, D7; outputs in D2, D3, D4
  586.  *        DoText - (see I-391)
  587.  *            Register-based; inputs in A3, D3, D4, D7; outputs in A0, D0
  588.  *        GNEFilterProc - (see tech note 85)
  589.  *            Register & Stack Based; inputs in A1, D0 & on the stack; outputs on the stack
  590.  *        MenuBarHook - (see I-356)
  591.  *            Register & Stack Based; input on the stack; output in D0
  592. */
  593. #define SPECIAL_CASE_PROCINFO(specialCaseCode)            \
  594.         (kSpecialCase | ((ProcInfoType)(specialCaseCode) << 4))
  595.  
  596.  
  597. /* * * * * * * * * * * * * * * 
  598.  *    STACK_UPP_TYPE    - used in typedefs to create ≈UPP type
  599.  *    REGISTER_UPP_TYPE - used in typedefs to create ≈UPP type
  600.  *
  601.  *    Example:
  602.  *
  603.  *        typedef STACK_UPP_TYPE(ModalFilterProcPtr)         ModalFilterUPP;
  604.  *        typedef REGISTER_UPP_TYPE(IOCompletionProcPtr)     IOCompletionUPP;
  605.  *
  606.  */
  607. #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  608.     /* classic 68k runtime */
  609.     #define STACK_UPP_TYPE(name)     name
  610.     #define REGISTER_UPP_TYPE(name) Register68kProcPtr
  611. #elif TARGET_OS_MAC && TARGET_RT_MAC_CFM
  612.     /* PowerPC and CFM68K runtime */
  613.     #define STACK_UPP_TYPE(name)     UniversalProcPtr
  614.     #define REGISTER_UPP_TYPE(name) UniversalProcPtr
  615. #else
  616.     /* other runtimes */
  617.     #define STACK_UPP_TYPE(name)     name
  618.     #define REGISTER_UPP_TYPE(name) name
  619. #endif
  620.  
  621.  
  622. /* * * * * * * * * * * * * * * 
  623.  *    CALL_≈_PARAMETER_UPP  - used in Call≈Proc macros
  624.  *
  625.  *    Example:
  626.  *
  627.  *        #define CallIOCompletionProc(userRoutine, paramBlock)     \
  628.  *                CALL_TWO_PARAMETER_UPP((userRoutine), uppIOCompletionProcInfo, (paramBlock))
  629.  *
  630.  */
  631. #if TARGET_OS_MAC && TARGET_RT_MAC_CFM
  632.     #define CALL_ZERO_PARAMETER_UPP(    upp, procInfo)         CallUniversalProc(upp, procInfo)
  633.     #define CALL_ONE_PARAMETER_UPP(     upp, procInfo, p1)         CallUniversalProc(upp, procInfo, (p1))
  634.     #define CALL_TWO_PARAMETER_UPP(     upp, procInfo, p1, p2)         CallUniversalProc(upp, procInfo, (p1), (p2))
  635.     #define CALL_THREE_PARAMETER_UPP(   upp, procInfo, p1, p2, p3)         CallUniversalProc(upp, procInfo, (p1), (p2), (p3))
  636.     #define CALL_FOUR_PARAMETER_UPP(    upp, procInfo, p1, p2, p3, p4)         CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4))
  637.     #define CALL_FIVE_PARAMETER_UPP(    upp, procInfo, p1, p2, p3, p4, p5)         CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5))
  638.     #define CALL_SIX_PARAMETER_UPP(     upp, procInfo, p1, p2, p3, p4, p5, p6)         CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6))
  639.     #define CALL_SEVEN_PARAMETER_UPP(   upp, procInfo, p1, p2, p3, p4, p5, p6, p7)         CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7))
  640.     #define CALL_EIGHT_PARAMETER_UPP(   upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8)         CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8))
  641.     #define CALL_NINE_PARAMETER_UPP(    upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9)         CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9))
  642.     #define CALL_TEN_PARAMETER_UPP(     upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)     CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10))
  643.     #define CALL_ELEVEN_PARAMETER_UPP(  upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11)     CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11))
  644.     #define CALL_TWELVE_PARAMETER_UPP(  upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12)    CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11), (p12))
  645.     #define CALL_THIRTEEN_PARAMETER_UPP(upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13)    CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11), (p12), (p13))
  646. #else
  647.     #define CALL_ZERO_PARAMETER_UPP(    upp, procInfo)         (*(upp))()
  648.     #define CALL_ONE_PARAMETER_UPP(     upp, procInfo, p1)         (*(upp))((p1))
  649.     #define CALL_TWO_PARAMETER_UPP(     upp, procInfo, p1, p2)         (*(upp))((p1), (p2))
  650.     #define CALL_THREE_PARAMETER_UPP(   upp, procInfo, p1, p2, p3)         (*(upp))((p1), (p2), (p3))
  651.     #define CALL_FOUR_PARAMETER_UPP(    upp, procInfo, p1, p2, p3, p4)         (*(upp))((p1), (p2), (p3), (p4))
  652.     #define CALL_FIVE_PARAMETER_UPP(    upp, procInfo, p1, p2, p3, p4, p5)         (*(upp))((p1), (p2), (p3), (p4), (p5))
  653.     #define CALL_SIX_PARAMETER_UPP(     upp, procInfo, p1, p2, p3, p4, p5, p6)         (*(upp))((p1), (p2), (p3), (p4), (p5), (p6))
  654.     #define CALL_SEVEN_PARAMETER_UPP(   upp, procInfo, p1, p2, p3, p4, p5, p6, p7)         (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7))
  655.     #define CALL_EIGHT_PARAMETER_UPP(   upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8)         (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8))
  656.     #define CALL_NINE_PARAMETER_UPP(    upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9)         (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9))
  657.     #define CALL_TEN_PARAMETER_UPP(     upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)     (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10))
  658.     #define CALL_ELEVEN_PARAMETER_UPP(  upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11)     (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11))
  659.     #define CALL_TWELVE_PARAMETER_UPP(  upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12)     (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11), (p12))
  660.     #define CALL_THIRTEEN_PARAMETER_UPP(upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13)     (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11), (p12), (p13))
  661. #endif
  662.  
  663.  
  664.  
  665.  
  666.  
  667. #if PRAGMA_STRUCT_ALIGN
  668.     #pragma options align=reset
  669. #elif PRAGMA_STRUCT_PACKPUSH
  670.     #pragma pack(pop)
  671. #elif PRAGMA_STRUCT_PACK
  672.     #pragma pack()
  673. #endif
  674.  
  675. #ifdef PRAGMA_IMPORT_OFF
  676. #pragma import off
  677. #elif PRAGMA_IMPORT
  678. #pragma import reset
  679. #endif
  680.  
  681. #ifdef __cplusplus
  682. }
  683. #endif
  684.  
  685. #endif /* __MIXEDMODE__ */
  686.  
  687.